﻿CREATE PROCEDURE [dbo].[SaveRun]
(@RunID varchar(50),
@WorkflowID varchar(50), 
@TriggerInstanceID varchar(50), 
@SubmitTime datetime,
@StartTime datetime, 
@FinishTime datetime, 
@Vars text) as 
begin
	declare @count int 
	set @count =(select count (*) from Runs where RunID=@RunID)
	if @count > 0 
	begin
		update Runs 
		set 
			WorkflowID=@WorkflowID,
			TriggerInstanceID=@TriggerInstanceID,
			SubmitTime=@SubmitTime,
			StartTime=@StartTime,
			FinishTime=@FinishTime, 
			Vars=@Vars 
		where 
			RunID=@RunID
	end
	else
	begin
		insert into Runs 
			(RunID,
			WorkflowID,
			TriggerInstanceID,
			SubmitTime,
			StartTime,
			FinishTime, 
			Vars) values 
			(@RunID,
			@WorkflowID,
			@TriggerInstanceID,
			@SubmitTime,
			@StartTime,
			@FinishTime,
			@Vars)
	end
end


